
package cn.tang.tframe.dynconfig.parser;

import cn.tang.tframe.common.utils.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * Created by tanghc
 */
public abstract class ConfigValueParser<V> {

	protected final Logger logger =
		LoggerFactory.getLogger(this.getClass());
	public V parse(Properties properties,String key,V defaultValue){
		if(null != properties){
			Object o = properties.get(key);
			if(null != o ){
				String v = o.toString();
				if(StringUtils.isNotBlank(v)){
					return doParse(v);
				}
			}
		}
		if(null != defaultValue){
			return defaultValue;
		}
		throw new RuntimeException("no or invalid dynconfig for " + key);
	}
	public abstract V doParse(String v);
}
